package com.huluobo.a2211mdmdemo

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController

/**
 *  Created by LC on 2025/4/22.
 */
@Composable
fun demo04() {
    //考航控制器
    val navHostController = rememberNavController()

    NavHost(navController = navHostController, startDestination = "main", builder = {
        composable("main") { OnePage(navHostController) }
        composable("sec/{asdasd}") {
            val string = it.arguments?.getString("asdasd").toString()
            SecondPage(navHostController, string)
        }
    })
}

@Composable
fun OnePage(navHostController: NavHostController) {
    Text(text = "主页面",
        Modifier
            .fillMaxSize()
            .background(Color.Yellow)
            .clickable {
                navHostController.navigate("sec/123")
            })
}

@Composable
fun SecondPage(navHostController: NavHostController, str: String) {
    Text(text = "第二页面:$str",
        Modifier
            .fillMaxSize()
            .background(Color.Green)
            .clickable {
                navHostController.navigate("main")
            })
}